from fastapi import APIRouter

from base.bean.beans import ApiCurrentConfigBean
from base.util.api_util import ApiUtil
from capture_api import currentConfigDao

currentConfigRouter = APIRouter()


@currentConfigRouter.post('/get_current_config_file',description="获取当前配置文件")
def get_current_config_file():
    current = currentConfigDao.get_current_config()
    if current:
        return ApiUtil.wrap_correct({
            "config_id": current.config_id,
            "description": current.description,
        })
    else:
        return ApiUtil.wrap_error("获取当前配置失败")


@currentConfigRouter.post('/setup_current_config_file',description="设置当前使用的文件")
def setup_current_config_file(bean: ApiCurrentConfigBean):
    try:
        currentConfigDao.set_current_config(id=bean.id, desc=bean.description)
        return ApiUtil.wrap_correct("设置成功")
    except Exception as e:
        return ApiUtil.wrap_error(str(e))
